#include "FPSCamera.h"
#include <math.h>


FPSCamera::FPSCamera(void)
{
	Camera::Camera();
	moveSpeed = 0.01f;
	rotationSpeed = 0.01f;		
}

FPSCamera::~FPSCamera(void)
{
	Camera::~Camera();
}

void FPSCamera::AddToPosition(XMVECTOR vector)
{
	XMMATRIX cameraRotation = XMMatrixRotationAxis(XMVectorSet(0.0f,1.0f,0.0f,0),yaw) * XMMatrixRotationAxis(XMVectorSet(1.0f,0.0f,0.0f,0),pitch);
	XMVECTOR rotatedVector = XMVector3Transform(vector, cameraRotation);
	position -= moveSpeed * rotatedVector;
}

void FPSCamera::UpdateCamera(int elapsedTime)
{	
	if(EngineStuff::EInputManager->isKeyPressed(DIK_W))
	{
		AddToPosition(XMVectorSet(0,0,1,0));
	}
	if(EngineStuff::EInputManager->isKeyPressed(DIK_S))
	{
		AddToPosition(XMVectorSet(0,0,-1,0));
	}
	if(EngineStuff::EInputManager->isKeyPressed(DIK_A))
	{
		AddToPosition(XMVectorSet(-1,0,0,0));
	}
	if(EngineStuff::EInputManager->isKeyPressed(DIK_D))
	{
		AddToPosition(XMVectorSet(1,0,0,0));
	}
	if(EngineStuff::EInputManager->isKeyPressed(DIK_Z))
	{
		AddToPosition(XMVectorSet(0,1,0,0));
	}
	if(EngineStuff::EInputManager->isKeyPressed(DIK_Q))
	{
		AddToPosition(XMVectorSet(0,-1,0,0));
	}

	int newx,newy;
	EngineStuff::EInputManager->GetRelativeMouseLocation(newx,newy);
	AddYawPitchRoll( newx * rotationSpeed ,-newy * rotationSpeed ,0);

	Camera::UpdateCamera(elapsedTime);
}
